﻿package org.xhs.report.common.ui.panel
{
    import __AS3__.vec.*;
    import baidu.ui.controls.*;
    import baidu.ui.managers.*;
    import baidu.wenku.common.*;
    import baidu.wenku.common.model.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class RelativePanel extends Sprite implements IPanel
    {
        protected var hasDestroyed:Boolean = true;
        protected var closeBtn:Button;
        protected var screenModel:ScreenModel;
        protected var relativeModel:RelativeModel;
        protected var itemArray:Vector.<Sprite>;
        public static const CLOSE_CLICK:String = "close_click";

        public function RelativePanel()
        {
            this.init();
            return;
        }// end function

        protected function init() : void
        {
            this.relativeModel = InstanceManager.createSingletonInstance(RelativeModel);
            this.relativeModel.addEventListener(RelativeModel.OPEN_PANEL, this.openPanel);
            this.relativeModel.addEventListener(RelativeModel.CLOSE_PANEL, this.closePanel);
            this.screenModel = InstanceManager.createSingletonInstance(ScreenModel);
            this.screenModel.addEventListener(Event.RESIZE, this.screenResize);
            return;
        }// end function

        protected function screenResize(event:Event) : void
        {
            x = this.screenModel.stageWidth - width;
            y = this.screenModel.stageHeight - Config.SB_HEIGHT - height + 1;
            return;
        }// end function

        protected function closeBtnClick(event:MouseEvent) : void
        {
            dispatchEvent(new Event(RelativePanel.CLOSE_CLICK));
            return;
        }// end function

        protected function openPanel(event:Event) : void
        {
            this.resetPanel();
            return;
        }// end function

        protected function closePanel(event:Event) : void
        {
            this.destroy();
            return;
        }// end function

        public function resetPanel() : void
        {
            var _loc_1:Number = NaN;
            var _loc_2:Number = NaN;
            var _loc_3:Sprite = null;
            var _loc_10:int = 0;
            var _loc_13:Sprite = null;
            var _loc_14:Sprite = null;
            var _loc_15:Sprite = null;
            var _loc_16:TextField = null;
            var _loc_17:String = null;
            if (!this.hasDestroyed || !this.relativeModel.dataArray)
            {
                return;
            }
            this.screenModel.addStageMask();
            _loc_1 = 226;
            _loc_2 = 26;
            _loc_3 = new Sprite();
            var _loc_4:* = new TextField();
            var _loc_5:* = new TextFormat("宋体", 12, 0, true);
            _loc_4.selectable = false;
            _loc_4.autoSize = "left";
            _loc_4.text = "相关文档";
            _loc_4.setTextFormat(_loc_5);
            _loc_3.addChild(_loc_4);
            _loc_4.x = 5;
            _loc_4.y = 5;
            var _loc_6:* = _loc_3.graphics;
            _loc_3.graphics.lineStyle(1, Config.BORDER_COLOR);
            _loc_6.beginFill(15266295);
            _loc_6.drawRect(0, 0, _loc_1, (_loc_2 - 1));
            _loc_6.endFill();
            addChild(_loc_3);
            var _loc_7:* = new StyleSheet();
            var _loc_8:* = new Object();
            new Object().color = "#322aca";
            _loc_7.setStyle("a:hover", _loc_8);
            var _loc_9:* = this.relativeModel.dataArray.length;
            this.itemArray = new Vector.<Sprite>;
            _loc_10 = 0;
            while (_loc_10 < _loc_9)
            {
                
                _loc_13 = new Sprite();
                _loc_6 = _loc_13.graphics;
                _loc_6.lineStyle();
                _loc_6.beginFill(_loc_10 % 2 == 0 ? (16777215) : (15858167));
                _loc_6.drawRect(1, 0, (_loc_1 - 1), _loc_2);
                _loc_6.endFill();
                _loc_14 = new TypeIcon();
                _loc_15 = new Sprite();
                _loc_15.addChild(_loc_14[this.relativeModel.dataArray[_loc_10].docType] || _loc_14["txt"]);
                _loc_13.addChild(_loc_15);
                _loc_15.x = 5;
                _loc_15.y = (_loc_2 - _loc_15.height) / 2;
                _loc_16 = new TextField();
                _loc_16.selectable = false;
                _loc_16.width = _loc_1 - 30;
                _loc_16.height = 18;
                _loc_16.styleSheet = _loc_7;
                _loc_17 = this.relativeModel.dataArray[_loc_10].title;
                _loc_17 = _loc_17.replace(/&""&/gi, "&amp;").replace(/<""</gi, "&lt;").replace(/>"">/gi, "&gt;").replace(/\\""""\"/gi, "&quot;").replace(/\\''""\'/gi, "&apos;");
                _loc_16.htmlText = "<FONT FACE=\'宋体\' SIZE=\'12\' COLOR=\'#0e4982\'><a target=\'_blank\' href=\'" + this.relativeModel.dataArray[_loc_10].link + "\'>" + _loc_17 + "</a></FONT>";
                _loc_13.addChild(_loc_16);
                _loc_16.x = 25;
                _loc_16.y = (_loc_2 - _loc_16.height) / 2;
                this.itemArray.push(_loc_13);
                addChild(_loc_13);
                _loc_13.x = 0;
                _loc_13.y = (_loc_10 + 1) * _loc_2;
                _loc_10++;
            }
            var _loc_11:* = new TextField();
            new TextField().selectable = false;
            _loc_11.autoSize = "left";
            _loc_11.htmlText = "<FONT FACE=\'宋体\' SIZE=\'12\' COLOR=\'#737373\'><u><a target=\'_blank\' href=\'" + this.relativeModel.moreUrl + "\'>到文库查看更多文档 >></a></u></FONT>";
            addChild(_loc_11);
            _loc_11.x = (_loc_1 - _loc_11.width) / 2;
            _loc_11.y = (_loc_9 + 1) * _loc_2 + (_loc_2 - _loc_11.height) / 2;
            var _loc_12:* = new AllSkins();
            this.closeBtn = new Button();
            this.closeBtn.setStyle("skin", _loc_12["skin_relativeclose"]);
            this.closeBtn.x = _loc_1 - 21;
            this.closeBtn.y = 5;
            this.closeBtn.useHandCursor = true;
            addChild(this.closeBtn);
            this.closeBtn.addEventListener(MouseEvent.CLICK, this.closeBtnClick);
            _loc_6 = graphics;
            _loc_6.clear();
            _loc_6.lineStyle(1, Config.BORDER_COLOR);
            _loc_6.beginFill(16777215);
            _loc_6.drawRect(0, 0, _loc_1, _loc_2 * (_loc_9 + 2));
            _loc_6.endFill();
            this.screenModel.stage.addChild(this);
            x = this.screenModel.stageWidth - width;
            y = this.screenModel.stageHeight - Config.SB_HEIGHT - height + 1;
            this.hasDestroyed = false;
            return;
        }// end function

        public function destroy() : void
        {
            var _loc_2:DisplayObject = null;
            if (this.hasDestroyed)
            {
                return;
            }
            this.closeBtn.removeEventListener(MouseEvent.CLICK, this.closeBtnClick);
            var _loc_1:int = 0;
            while (_loc_1 < this.itemArray.length)
            {
                
                _loc_1++;
            }
            this.itemArray = null;
            while (this.numChildren > 0)
            {
                
                _loc_2 = getChildAt(0);
                this.removeChildAt(0);
                _loc_2 = null;
            }
            this.screenModel.removeStageMask();
            if (this.screenModel.stage.contains(this))
            {
                this.screenModel.stage.removeChild(this);
            }
            this.hasDestroyed = true;
            return;
        }// end function

    }
}
